package leetcode;

import java.util.Arrays;
import java.util.HashMap;

public class Q0205 {
    public boolean isIsomorphic(String s, String t) {
        if (s.length() != t.length()) return false;
        HashMap<Character, Character> mapst = new HashMap<>();
        HashMap<Character, Character> mapts = new HashMap<>();
        for (int i = 0; i < s.length(); i++) {
            if (!mapst.containsKey(s.charAt(i)) && !mapts.containsKey(t.charAt(i))) {
                mapst.put(s.charAt(i), t.charAt(i));
                mapts.put(t.charAt(i), s.charAt(i));
            } else if (mapst.containsKey(s.charAt(i)) && mapts.containsKey(t.charAt(i))) {
                if ((mapst.get(s.charAt(i)) != t.charAt(i)) || (mapts.get(t.charAt(i)) != s.charAt(i))) return false;
            } else {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        Q0205 sl = new Q0205();
        sl.isIsomorphic("123", "123");
    }
}
